#include "user.pb.h"
#include <string>
#include <iostream>
#include "rpcprovider.h"
#include "mprpcapplication.h"
#include "logger.h"

class UserService : public Asukai::UserServiceRpc
{
public:
    bool Login(std::string name, std::string password)
    {
        std::cout << "name:" << name << "password:" << password << std::endl;
        return true;
    }

    void Login(::google::protobuf::RpcController *controller,
               const ::Asukai::LoginRequest *request,
               ::Asukai::LoginResponse *response,
               ::google::protobuf::Closure *done)
    {
        bool login_res = Login(request->username(), request->password());

        Asukai::ResultCode *res = response->mutable_result();
        res->set_errcode(0);
        res->set_errmsg("");
        response->set_success(login_res);

        done->Run();
    }
};

int main(int argc, char* argv[])
{
    MprpcApplication::init(argc, argv);
    LOG_INFO("init success");
    RpcProvider provider;
    provider.NotifyService(new UserService());

    provider.Run();
}